﻿using Core.Toolkit.PagingQuery;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

namespace Core.SimpleTemp.Common.PagingQuery
{
    public class PagingModelBase<TEntity>
    {

        public virtual int Offset { get; set; } = 10;
        [Range(1, SysConsts.PAGING_MAXI_LIMIT, ErrorMessage = "非法的Limit")]
        public virtual int Limit { get; set; }
    }

    public class PagingModel<TEntity> : PagingModelBase<TEntity>
    {
        public TEntity Model { get; set; }
        public List<OrderModel> OrderList { get; set; } = new List<OrderModel>();
    }

    public class LoadPageOffsetBaseModel<TEntity, Tdto> : PagingModel<Tdto>
    {
        public Expression<Func<TEntity, object>> Order { get; set; }
        public Expression<Func<TEntity, object>> Selector { get; set; }
        public IQueryable<TEntity> BasqQuery { get; set; }
        public Func<IQueryable<TEntity>, IQueryable<TEntity>> BeginSelectEventAction { get; set; }
    }

    public class LoadPageOffsetModelAuto<TEntity, Tdto> : LoadPageOffsetBaseModel<TEntity, Tdto>
    {
        public List<QueryRules> QueryWhere { get; set; }
    }
    [CreateMap(typeof(PagingModel<>))]
    public class LoadPageOffsetModel<TEntity, Tdto> : LoadPageOffsetBaseModel<TEntity, Tdto>
    {
        public Expression<Func<TEntity, bool>> QueryWhere { get; set; }
    }

    public sealed class OrderModel
    {
        public string PropertyName { get; set; }
        public bool IsDesc { get; set; }
    }

}